﻿using System.ComponentModel;
using Loki.Utils;
using Luna.Data.Budget;

namespace Luna.Model.Budget
{
    internal class Category : LunaEntity<ICategoryData>, ICategory, IEditableCategory
    {
        #region Color

        private static PropertyChangedEventArgs _ColorChangedArgs = ObservableHelper.CreateChangedArgs<Category>(x => x.Color);

        private static PropertyChangingEventArgs _ColorChangingArgs = ObservableHelper.CreateChangingArgs<Category>(x => x.Color);

        public string Color
        {
            get
            {
                return Data.Color;
            }

            set
            {
                if (value != Data.Color)
                {
                    NotifyChanging(_ColorChangingArgs);
                    Data.Color = value;
                    NotifyChangedAndDirty(_ColorChangedArgs);
                }
            }
        }

        #endregion Color

        #region Name

        private static PropertyChangedEventArgs _NameChangedArgs = ObservableHelper.CreateChangedArgs<Category>(x => x.Name);

        private static PropertyChangingEventArgs _NameChangingArgs = ObservableHelper.CreateChangingArgs<Category>(x => x.Name);

        public string Name
        {
            get
            {
                return Data.Name;
            }

            set
            {
                if (value != Data.Name)
                {
                    NotifyChanging(_NameChangingArgs);
                    Data.Name = value;
                    NotifyChangedAndDirty(_NameChangedArgs);
                }
            }
        }

        #endregion Name

        #region Description

        private static PropertyChangedEventArgs _DescriptionChangedArgs = ObservableHelper.CreateChangedArgs<Category>(x => x.Description);

        private static PropertyChangingEventArgs _DescriptionChangingArgs = ObservableHelper.CreateChangingArgs<Category>(x => x.Description);

        public string Description
        {
            get
            {
                return Data.Description;
            }

            set
            {
                if (value != Data.Description)
                {
                    NotifyChanging(_DescriptionChangingArgs);
                    Data.Description = value;
                    NotifyChangedAndDirty(_DescriptionChangedArgs);
                }
            }
        }

        #endregion Description

        public Category()
            : base()
        {
            Name = "Nouvelle categorie";
        }

        public Category(Category P_Base)
            : base(P_Base)
        {
            BeginInit();

            Name = P_Base.Name;
            Description = P_Base.Description;
            Color = P_Base.Color;

            EndInit(!IsChanged);
        }

        public Category(ICategoryData P_Data)
            : base(P_Data)
        {
        }

        public IEditableCategory EditableCopy
        {
            get { return new Category(this); }
        }
    }
}